/*
#asset(qx/icon/${qx.icontheme}/16/actions/)
#asset(qx/icon/${qx.icontheme}/16/apps/)
*/
qx.Class.define("qx.ui.form.ow.Editor",
{
	extend : qx.ui.core.Widget,
	construct : function (width, height, noCSS)
	{
		this.base(arguments);

		this._setLayout(new qx.ui.layout.VBox(1));

		this._page = new qx.ui.form.ow.Page(width, height, noCSS);
		var btnB = new qx.ui.form.Button("B");
		btnB.addListener("execute", function () { this._page.bold(); }, this);

		this._add(this._Basic());
		this._add(this._page);
	},
	members :
	{
		_page : null,
		_Basic : function()
		{
			var frame = new qx.ui.container.Composite(new qx.ui.layout.Grow);
			frame.setDecorator("main");

			var toolbar = new qx.ui.toolbar.ToolBar;
			frame.add(toolbar);

			var partOne = new qx.ui.toolbar.Part;
			var partTwo = new qx.ui.toolbar.Part;
			var partThree = new qx.ui.toolbar.Part;
			var partFour = new qx.ui.toolbar.Part;

			toolbar.add(partOne);
			toolbar.add(partTwo);
			toolbar.add(partThree);
			toolbar.addSpacer();
			toolbar.add(partFour);

			// ****** PART ONE *******
			var btnUndo = new qx.ui.toolbar.Button("Undo", "icon/16/actions/edit-undo.png");
			var btnRedo = new qx.ui.toolbar.Button("Redo", "icon/16/actions/edit-redo.png");

			var btnBold = new qx.ui.toolbar.Button("B", "icon/16/actions/format-text-bold.png");
			var btnItalic = new qx.ui.toolbar.Button("I", "icon/16/actions/format-text-italic.png");
			var btnUnderline = new qx.ui.toolbar.Button("U", "icon/16/actions/format-text-underline.png");
			var btnStrikethrough = new qx.ui.toolbar.Button("S", "icon/16/actions/format-text-strikethrough.png");

			btnUndo.addListener("execute", function () { this._page.undo(); }, this);
			btnRedo.addListener("execute", function () { this._page.redo(); }, this);

			btnBold.addListener("execute", function () { this._page.bold(); }, this);
			btnItalic.addListener("execute", function () { this._page.italic(); }, this);
			btnUnderline.addListener("execute", function () { this._page.underline(); }, this);
			btnStrikethrough.addListener("execute", function () { this._page.strikethrough(); }, this);

			partOne.add(btnUndo);
			partOne.add(btnRedo);
			partOne.addSeparator();
			partOne.add(btnBold);
			partOne.add(btnItalic);
			partOne.add(btnUnderline);
			partOne.add(btnStrikethrough);
			partOne.setShow("icon");

			// ****** PART TWO *******
			var btnAlignLeft = new qx.ui.toolbar.Button("A_L", "icon/16/actions/format-justify-left.png");
			var btnAlignCenter = new qx.ui.toolbar.Button("A_C", "icon/16/actions/format-justify-center.png");
			var btnAlignRight = new qx.ui.toolbar.Button("A_R", "icon/16/actions/format-justify-right.png");
			var btnAlignJustify = new qx.ui.toolbar.Button("A_J", "icon/16/actions/format-justify-fill.png");

			var btnIndentDecrease = new qx.ui.toolbar.Button("I_D", "icon/16/actions/format-indent-less.png");
			var btnIndentIncrease = new qx.ui.toolbar.Button("I_I", "icon/16/actions/format-indent-more.png");

			btnAlignLeft.addListener("execute", function () { this._page.alignLeft(); }, this);
			btnAlignCenter.addListener("execute", function () { this._page.alignCenter(); }, this);
			btnAlignRight.addListener("execute", function () { this._page.alignRight(); }, this);
			btnAlignJustify.addListener("execute", function () { this._page.alignJustify(); }, this);

			btnIndentDecrease.addListener("execute", function () { this._page.indentDecrease(); }, this);
			btnIndentIncrease.addListener("execute", function () { this._page.indentIncrease(); }, this);

			partTwo.add(btnAlignLeft);
			partTwo.add(btnAlignCenter);
			partTwo.add(btnAlignRight);
			partTwo.add(btnAlignJustify);
			partTwo.addSeparator();
			partTwo.add(btnIndentDecrease);
			partTwo.add(btnIndentIncrease);
			partTwo.setShow("icon");

			// ****** PART THREE ******
			var btnLink = new qx.ui.toolbar.Button("Link", "icon/16/actions/insert-link.png");
			var btnImage = new qx.ui.toolbar.Button("Img", "icon/16/actions/insert-image.png");
			var btnTable = new qx.ui.toolbar.Button("Table", "icon/16/apps/office-spreadsheet.png");

			btnLink.addListener("execute", function () {
				this._page.link(prompt("Enter a URL:", "http://"));
			}, this);

			btnImage.addListener("execute", function () {
				this._page.image(prompt("Enter Image URL:", "http://"));
			}, this);

			btnTable.addListener("execute", function () { this._page.table(2,3); }, this);

			partThree.add(btnLink);
			partThree.add(btnImage);
			partThree.add(btnTable);
			partThree.setShow("icon");

			// ****** PART FOUR *******
			var btnSave = new qx.ui.toolbar.Button("Link", "icon/16/actions/document-save.png");

			btnSave.addListener("execute", function () { alert(this._page.getValue()); }, this);

			partFour.add(btnSave);
			partFour.setShow("icon");
			return frame;
		}
	}
});
